package com.cloud.stream2.sender;

import com.cloud.stream2.sender.output.TopicSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * @author shengtao
 * @Description:
 * @date 2019/06/04 11:07
 */
@Service
@EnableBinding(TopicSource.class)
public class SendService {

    @Autowired
    private TopicSource topicSource;

    public void sendMsg(Object obj){
        Map<String,Object> headers = new HashMap<>();
        headers.put("key","hahaha");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        GenericMessage message = new GenericMessage(obj);
        topicSource.outputChannel().send(message);
        System.out.println("===== 发送完成 =====");
    }

}
